// pages/index/function/storage/create-storage/create-storage.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [{
      id: 1,
      title: '园艺大师抗皱精华露',
      image: '../../../../../image/timg.jpg',
      pro_name: "30ml",
      num: 1,
      price: 180,
      selected: false
    },
    {
      id: 2,
      title: '伊芙琳玫瑰护手霜',
      image: '../../../../../image/timg.jpg',
      pro_name: "25g",
      num: 1,
      price: 62,
      selected: false
    },
    {
      id: 2,
      title: '燕麦山羊乳舒缓护手霜',
      image: '../../../../../image/timg.jpg',
      pro_name: "75ml",
      num: 1,
      price: 175,
      selected: false
    }
    ],
  },
  btn_add(e) {
    // 获取点击的索引
    const index = e.currentTarget.dataset.index;
    // 获取商品数据
    let list = this.data.list;
    // 获取商品数量
    let num = list[index].num;
    // 点击递增
    num = num + 1;
    list[index].num = num;
    // 重新渲染 ---显示新的数量
    this.setData({
      list: list
    });
    // 计算金额方法
    //this.count_price();
    //this.count_num();
  },
  //下载图片
  onShow1: function (object) {
    let _this = this;
    _this.setData({
      isShowCav: true
    })
    wx.downloadFile({
      url: object.avatarurl,
      success: function (sres) {
        _this.setData({
          canvasUserPic: sres.tempFilePath
        });
        wx.downloadFile({
          url: object.show_img,
          success: function (sres1) {
            _this.setData({
              canvasShowImg: sres1.tempFilePath
            });
            _this.canvas(object);
          }
        })
      }
    })
  },
  /**
   * 绑定减数量事件
   */
  btn_minus(e) {
    //   // 获取点击的索引
    const index = e.currentTarget.dataset.index;
    // const obj = e.currentTarget.dataset.obj;
    // console.log(obj);
    // 获取商品数据
    let list = this.data.list;
    // 获取商品数量
    let num = list[index].num;
    // 判断num小于等于1  return; 点击无效
    if (num <= 1) {
      return false;
    }
    // else  num大于1  点击减按钮  数量--
    num = num - 1;
    list[index].num = num;
    // 渲染页面
    this.setData({
      list: list
    });
    // 调用计算金额方法
   // this.count_price();
    //this.count_num();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

 goDetail:function(e){
   wx.navigateTo({
     url: '../storage-detail/storage-detail',
   })
 }
})